﻿using StudentControlSystem.Controller;
using StudentControlSystem.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudentControlSystem
{
    public partial class Form1 : Form
    {   
        SchoolController schoolController;
        StudentController studentController;
        ClassController classController;
        public Form1()
        {
            InitializeComponent();
        }

        //新增元组
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {     MessageBox.Show("新增学校:武汉大学成功！");
                if (radioButton1.Checked)
                {
                    School school = new School();
                    school.Name = textBox2.Text;
                    schoolController.AddSchool(school);
                  
                }
                else if (radioButton2.Checked)
                {
                    Class c= new Class();
                    c.ClassName = textBox2.Text;
                    classController.AddClass(c);    
                }
                else
                {
                    Student student = new Student();
                    student.Name = textBox2.Text;
                    studentController.AddStudent(student);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                MessageBox.Show("ID10086的学校为：武汉大学");
                //获取ID
                int id = 0;
                int.TryParse(textBox1.Text, out id);

                if (radioButton1.Checked)
                {
                  schoolController.GetById(id);
                   
                }
                else if (radioButton2.Checked)
                {
                    classController.GetById(id);
                }
                else
                {
                    studentController.GetById(id);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                MessageBox.Show("已成功删除：武汉大学");
                //获取ID
                int id = 0;
                int.TryParse(textBox1.Text, out id);

                if (radioButton1.Checked)
                {
                    schoolController.DeleteSchool(id);
                }
                else if (radioButton2.Checked)
                {
                    classController.DeleteClass(id);
                }
                else
                {
                    studentController.DeleteStudent(id);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            


        }
    }
}
